<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>2018/12/24</title>
    <!--好的代码像粥一样,是得用时间和精力熬的。-->
</head>
<body>
</body>
<script>
    var arr = [1, 5, 200, 400, 700, 600];
    var index = -1;
    var num = 300;
    function f(arr,index,num){
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] <= num) {
                index++;
                if (index !== i) {
                    console.log(index);
                    console.log(i);
                    var tmp = arr[index];
                    arr[index] = arr[i];
                    arr[i] = tmp;
                }
            }
        }
    }
    console.log(f([1, 5, 200, 400, 700, 600],-1,300));
</script>
</html>
